<template>
    <div class="row list-panel">
        <order-detail :showOrderDetail="showOrderDetail" :order="order" :products="products" :orderId="orderId"
                      @onCancelNewModal="onCancel()"></order-detail>
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <ol class="breadcrumb">
                        <li><a>订单管理</a></li>
                        <li><a>订单列表</a></li>
                    </ol>
                </div>
                <div class="content-wrapper">
                    <el-form :inline="true" :model="formInline" class="demo-form-inline" label-width="80px"
                             size="small">
                        <el-form-item label="订单单号">
                            <el-input v-model="formInline.orderNumber" placeholder="订单单号"></el-input>
                        </el-form-item>
                        <el-form-item label="下单用户">
                            <el-input v-model="formInline.realName" placeholder="下单用户"></el-input>
                        </el-form-item>
                        <el-form-item label="下单日期">
                            <el-col :span="11">
                                <el-date-picker type="date" placeholder="选择日期" value-format="yyyy-MM-dd"
                                                v-model="formInline.fromDate" style="width: 100%;"></el-date-picker>
                            </el-col>
                            <el-col class="line" :span="2" style="text-align: center;font-size: 12px">到</el-col>
                            <el-col :span="11">
                                <el-date-picker type="date" placeholder="选择日期" value-format="yyyy-MM-dd"
                                                v-model="formInline.toDate" style="width: 100%;"></el-date-picker>
                            </el-col>
                        </el-form-item>
                        <el-form-item label="联系电话">
                            <el-input v-model="formInline.mobile" placeholder="用户电话"></el-input>
                        </el-form-item>
                        <el-form-item label="订单状态">
                            <el-select v-model="formInline.orderStatus" placeholder="订单状态" style="width:177px">
                                <el-option label="全部" value=""></el-option>
                                <el-option label="已取消" value="-1"></el-option>
                                <el-option label="待付款" value="1"></el-option>
                                <el-option label="待发货" value="2"></el-option>
                                <el-option label="待自提" value="3"></el-option>
                                <el-option label="已完成" value="4"></el-option>
                                <el-option label="待退款" value="5"></el-option>
                                <el-option label="已退款" value="6"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item style="float: right;">
                            <a class="revision-btn" href="javaScript:void(0)" @click="onSubmit()">搜 索</a>
                        </el-form-item>
                    </el-form>

<!--                    <div class="col-sm-12" style="padding: 12px 0px 12px 0px;">-->
<!--                        <div class="alert alert-info" style="margin-bottom: 0px">-->
<!--                            <a class="revision-btn" @click="exportOrder()">导出订单</a>-->
<!--                        </div>-->
<!--                    </div>-->

                    <template v-if="data != null">
                        <el-table ref="multipleTable" :data="data.list" tooltip-effect="dark" :border="true"
                                  align="center"
                                  class="list-table"
                                  :header-cell-style="{'background-color': '#F5F5F6'}" max-height="600"
                                  style="width: 100%">
                            <el-table-column type="selection" width="55" align="center">
                            </el-table-column>
                            <template v-for="columnName in columnNames">
                                <template v-if="columnName.prop === 'orderStatus'">
                                    <el-table-column align="center" :label="columnName.label" :prop="columnName.prop">
                                        <template slot-scope="scope">
                                            <span style="color:#1ab394;" v-if="scope.row.orderStatus === -1">已取消</span>
                                            <span style="color:#F00;" v-if="scope.row.orderStatus === 1">待付款</span>
                                            <span style="color:#F00;" v-if="scope.row.orderStatus === 2">待发货</span>
                                            <span style="color:#F00;" v-if="scope.row.orderStatus === 3">待自提</span>
                                            <span style="color:#1ab394;" v-if="scope.row.orderStatus === 4">已完成</span>
                                            <span style="color:#1ab394;" v-if="scope.row.orderStatus === 5">待退款</span>
                                            <span style="color:#1ab394;" v-if="scope.row.orderStatus === 6">已退款</span>
                                        </template>
                                    </el-table-column>
                                </template>
                                <template v-else>
                                    <el-table-column align="center" :key="columnName.prop" :label="columnName.label"
                                                     :prop="columnName.prop">
                                    </el-table-column>
                                </template>
                            </template>
                            <el-table-column label="操作" width="100" align="center">
                                <template slot-scope="scope">
                                    <el-button type="text" size="small" @click="orderDetail(scope.row)">详情</el-button>
                                </template>
                            </el-table-column>
                        </el-table>
                    </template>
                    <el-pagination style="float: right;margin-top: 10px" @size-change="handleSizeChange"
                                   @current-change="handleCurrentChange" :current-page.sync="data.currPage"
                                   :page-size="data.pageSize"
                                   layout="total, prev, pager, next" :total="data.totalCount">
                    </el-pagination>

                </div>
            </div>
        </div>
    </div>
</template>

<script>
    import orderDetail from './orderDetail'

    export default {
        name: 'OrderList',
        components: {
            orderDetail
        },
        data() {
            return {
                formInline: {
                },
                columnNames: [{
                    label: '订单号',
                    prop: 'orderNumber',
                    width: 180
                }, {
                    label: '下单客户',
                    prop: 'user.realName',
                    width: 120
                }, {
                    label: '联系电话',
                    prop: 'user.mobile',
                    width: 120
                }, {
                    label: '订单金额(元)',
                    prop: 'totalAmount',
                    width: 100
                }, {
                    label: '订单状态',
                    prop: 'orderStatus',
                    width: 100
                }, {
                    label: '所属团',
                    prop: 'store.storeName',
                    width: 180
                }, {
                    label: '创建日期',
                    prop: 'createTime',
                    width: 120
                }, {
                    label: '付款日期',
                    prop: 'payTime',
                    width: 120
                }, {
                    label: '发货日期',
                    prop: 'shipmentTime',
                    width: 120
                }],
                multipleSelection: [],
                data: {},
                query: {
                    page: ''
                },
                order: {order: {}, orderGoodsList: [], user: {}, store: {}},
                orderId: null,
                products: {list: []},
                showOrderDetail: false
            }
        },
        mounted: function () {
            this.listAllOrders();
        },
        methods: {
            async exportOrder() {
                this.$api.export('/mall/order/export', this.formInline);
            },
            getUrl() {
                return '/mall/order/export';
            },
            async onSubmit() {
                this.formInline.page = this.query.page;
                let res = await this.$api.get('/mall/order/list', this.formInline);
                if (res.code === 0) {
                    this.data = res.page;
                } else {
                    this.$message.error(res.msg);
                }
            },
            onCancel() {
                this.showOrderDetail = false
            },
            handleSizeChange(val) {
            },
            handleCurrentChange(val) {
                this.query.page = val;
                this.listAllOrders();
            },
            async orderDetail(item) {
                let res1 = await this.$api.get('/mall/ordergoods/list', {
                    orderId: item.orderId
                });
                let res2 = await this.$api.get('/mall/order/info/' + item.orderId)
                this.order = res2.order
                this.order.user = this.order.user?this.order.user:{}
                this.orderId = item.orderId.toString()
                this.products = res1.page
                this.showOrderDetail = true
            },
            async listAllOrders() {
                let res = await this.$api.get('/mall/order/list', this.query);
                if (res.code === 0) {
                    this.data = res.page;
                } else {
                    this.$message.error(res.msg);
                }
            }
        }
    }
</script>

<style scoped>
    .list-panel .content-wrapper /deep/ .el-form-item__label {
        font-family: "open sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
        color: #666;
        font-size: 12px;
        font-weight: normal;
    }

    .list-table {
        font-size: 12px;
    }
</style>
